﻿@model MaterialProcess
@{
    ViewBag.Title = "加工计划单编辑";
    Layout = "~/Views/Shared/_LayoutForm.cshtml";
}
@section Up{
@Html.HiddenFor(model => model.Id)
@Html.nbTextBoxFor(model => model.Code).Required()
@Html.nbDateFor(model => model.ProcessDate, "yyyy-MM-dd", new { style = "width:180px" }).Required()
@Html.nbTextBoxFor(model => model.TotalWeight).Required().Number()
@Html.nbDropDownListFor(model => model.Category, "MaterialCategory")
@Html.nbTextAreaFor(model => model.Remark)
}
@section Down{
    @Html.Css("flexigrid", "tmpl", "list")
    @Html.Js("flexigrid", "tmpl", "list")
    @(Html.nbGridFor<MaterialProcessItem>(s =>
    {
        s.ID("MaterialList");
        s.Action(@Url.Action("EditList"));
        s.ExtParam(new { OrderId = "$('#Id').val()", Category = @ViewBag.Category ?? "", date = @ViewBag.Date ?? "" });
        s.Width(580);
        s.Height(100);
        s.Columns(col =>
        {
            col.Bind(e => e.Id).IsKey().Sortable(false);
            col.Bind(e => e.Code).Width(60).Align(GridAlign.Left).Sortable(false);
            col.Bind(e => e.Name).Width(60).Align(GridAlign.Left).Sortable(false);
            col.BindEnum(e => e.RawMaterialId,"Material").Width(60).Sortable(false);
            col.BindEnum(e => e.Category, "MaterialCategory").Width(60).Sortable(false);
            col.Bind(e => e.ExpectedPickCount).Template(@Html.TextBox("ExpectedPickCount", "${ExpectedPickCount}", new { style = "text-align:right;width:56px" }).ToString()).Width(60).Sortable(false);
            col.Bind(e => e.ExpectedStorageCount).Template(@Html.TextBox("ExpectedStorageCount", "${ExpectedStorageCount}", new { style = "text-align:right;width:56px" }).ToString()).Width(60).Sortable(false);
            col.BindTemplate()
               .Template(Url.GridRowDeleteLink("Name"));
        });
        s.ShowCheckBox(false);
        s.UsePager(false);
        s.Buttons(b =>
        {
            b.Bind("Add", "选择品名", GridButtonType.Add).OnClick("SelectMaterial");
        });
    }))
}
<script type="text/javascript">
    function Additem(id) {
        var id = $("#Id").val();
        OpenModalDialog('@Url.Action("EditItem")?ParentId=' + id, { width: 480, height: 300, onclose: ReLoadMaterialList });
    }

    function SelectMaterial(e) {
        OpenModalDialog('@Url.Action("LookUp", "Material")',
        {
            width: 800,
            height: 500,
            type: 2,
            onclose:
            function (MaterialData) {
                if (MaterialData) {
                    $("#MaterialList").flexAddRows(MaterialData);
                }
            }
        });
    }

    function DeleteItem(Id) {
        $("#MaterialList")[0].childNodes[0].deleteRow();
        showLoadingMsg("删除成功！", { left: 300, top: 1 }, true, 3000);
    }

    function ReLoadMaterialList() {
        $("#MaterialList").flexReload();
    }
</script>